package club.babyf.nativeai.demo.algorithm;

/**
 * _32_IntegerReverse.
 *
 * @author zhanglei.
 * @date 2025/8/8 22:20.
 * @description 整数翻转.
 */
public class _32_IntegerReverse {

    public int integerReverse(int num) {
        int sign = num > 0 ? 1 : -1;
        if (num > 0) num = -num;
        int res = 0;
        while (num != 0) {
            int digit = num % 10;
            num /= 10;
            if (res < Integer.MIN_VALUE / 10 || (res == Integer.MIN_VALUE / 10 && digit < Integer.MIN_VALUE % 10)) {
                return 0;
            }
            res = res * 10 + digit;
        }
        return sign == 1 ? -res : res;
    }

    public static void main(String[] args) {
        _32_IntegerReverse integerReverse = new _32_IntegerReverse();
        System.out.println(integerReverse.integerReverse(1534236469));
    }

}
